package com.icid.store.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.icid.store.business.delegate.TestcodeDelegate;
	import com.icid.store.event.GetTestcodeListEvent;
	import com.icid.store.model.TestcodeModelLocator;
	import com.icid.store.vo.TestcodeVO;
	
	import mx.rpc.IResponder;

	public class GetTestcodeListCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:TestcodeDelegate;
		private var getTestcodeListEvent:GetTestcodeListEvent;
		private var testcodeModel:TestcodeModelLocator = TestcodeModelLocator.getInstance();
		public function GetTestcodeListCommand()
		{
			super();
			delegate = new TestcodeDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			getTestcodeListEvent = GetTestcodeListEvent(event);
			delegate.read(getTestcodeListEvent.tid);
		}
		
		override public function result(data:Object):void
		{
//			trace(data.result);
			testcodeModel.testcodeList.removeAll();
			for(var i:int=0;i<data.result.length;i++)
			{
				var testcodeVO:TestcodeVO = new TestcodeVO();
				
				testcodeVO.url = data.result[i].url;
				testcodeVO.id = data.result[i].id;
				testcodeVO.time = data.result[i].time;
				testcodeVO.title = data.result[i].title;
				testcodeVO.description = data.result[i].description;
				
				testcodeModel.testcodeList.addItem(testcodeVO);
			}
			testcodeModel.testcodeList.refresh();
		}
		
	}
}